use serde::Deserialize;
use tokio::runtime;
use tokio::runtime::Runtime;
use crate::APP_CONFIG;

/// 线程池配置项
#[derive(Debug, Deserialize, Clone)]
pub struct ThreadPoolConfig {
    /// 线程名称
    name: String,
    /// 最大线程数
    max_task: u64,
}

/// 线程池配置实现
impl ThreadPoolConfig {
    /// 初始化线程池
    pub fn init_thread_pool() -> Runtime {
        let max_task = APP_CONFIG.thread_pool.max_task as usize;

        runtime::Builder::new_multi_thread()
            .thread_name(&APP_CONFIG.thread_pool.name)
            .worker_threads(max_task)
            .enable_all()
            .build()
            .unwrap()
    }
}